#include "processbar.h"
#define NONE "\033[m"
#define GREEN "\033[0;32;32m"

const char *loading = "|/-\\";
char bar[num]={0};

void processbar(int rate)
{
	//第二种方式：把循环写到外面去，并且给进度条加上颜色
	int len = strlen(loading);
	//判断是否合法
	if(rate<0||rate>100)
		return;
	printf(GREEN"[%-100s]"NONE"[%d%%][%c]\r",bar,rate,loading[rate%len]);
	fflush(stdout);
	bar[rate++]=style;
	if(rate<=100)
		bar[rate]=tail;
	//int cnt=0;
	//char bar[num];
	//memset(bar,'\0',sizeof(bar));
	//int len = strlen(loading);
	//while(cnt<=top)
	//{
	//	printf("[%-100s][%d%%][%c]\r",bar,cnt,loading[cnt%len]);
	//	fflush(stdout);	
	//	usleep(speed);
	//	bar[cnt++] = style;
	//	bar[cnt]='>';
	//}
	//printf("\n");
}
void Initbar()
{
	memset(bar,'\0',sizeof(bar));
}
